package com.topfinance.cnaps2.web.sys;

import java.util.HashMap;
import java.util.List;

import com.topfinance.cnaps2.dto.SysOperDto;
import com.topfinance.cnaps2.service.ISysOperManager;
import com.topfinance.frame.util.StringUtil;
import com.topfinance.frame.web.BaseSupport;
import com.opensymphony.xwork2.ModelDriven;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author
 * @version 1.50
 *          <p>
 *          Copyright: Copyright (c) 2004 2005
 *          </p>
 *          <p>
 *          Company:
 *          </p>
 */
public final class SysOperAction extends BaseSupport implements ModelDriven<SysOperDto> {

	private ISysOperManager operManager = null;

	private SysOperDto operDto = new SysOperDto();

	public SysOperDto getModel() {
		return operDto;
	}

	public void setSysOperManager(ISysOperManager operManager) {
		this.operManager = operManager;
	}

	public SysOperAction() {
		super();
	}

	public String execute() {
		return list();
	}
	
	public String list() {
		log.debug("SysOperAction-list begin");
		try {
			List l = operManager.getAllOperList();
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, l);
			rtnResultMap.put(RECORDS_COUNT, l.size());
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("SysOperAction-list end");
		return SUCCESS;
	}

	public String listusroper() {
		log.debug("SysOperAction-list begin");
		try {
			String uid = request.getParameter("uid");
			List l = operManager.getUserOperList(uid);
			rtnResultMap = new HashMap();
			rtnResultMap.put(DATA_LIST_ROOT, l);
			rtnResultMap.put(RECORDS_COUNT, l.size());
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("SysOperAction-list end");
		return SUCCESS;
	}

	public String modifyusroper() {
		log.debug("SysOperAction-list begin");
		try {
			String uid = request.getParameter("uid");
			String fids = request.getParameter("fids");
			String enables = request.getParameter("enbs");
			operManager.modifyUserOper(uid,fids,enables);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			//args[0] = "" + orgDto.getOID();
			rtnResultMap.put("info", getText(UPDATE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("SysOperAction-list end");
		return SUCCESS;
	}
	
	public String create() {
		try {
			log.debug(StringUtil.mapObject(operDto));
			operManager.addOper(operDto);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			//args[0] = "" + orgDto.getOID();
			rtnResultMap.put("info", getText(CREATE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}
	
	public String update() {
		try {
			log.debug(StringUtil.mapObject(operDto));
			operManager.editOper(operDto);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			args[0] = "";// you can add extra message here.
			rtnResultMap.put("info", getText(UPDATE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}

	public String delete() {
		try {
			String delId = request.getParameter("id");
			operManager.deleteOper(new Integer(delId));
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", "true");
			String[] args = new String[1];
			args[0] = "";// you can add extra message here.
			rtnResultMap.put("info", getText(DELETE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}	

	public String test() {
		log.debug("SysUserAction-test begin");
		try {
			SysOperDto opDto = new SysOperDto();
			opDto.setFID(1002);
			opDto.setUID(1000);
			operManager.addOper(opDto);
			rtnResultMap = new HashMap();
			rtnResultMap.put("info", getText("create.success", "Test Success!"));
			return SUCCESS;
		} catch (Exception e) {
			handleException(e);
		}
		log.debug("SysUserAction-list end");
		return SUCCESS;
	}	
	
}
